#ifndef U2GLESPreRequest_H
#define U2GLESPreRequest_H

#include "U2PreRequest.h"



#if (U2_PLATFORM == U2_PLATFORM_APPLE_IOS)
#   include <OpenGLES/ES1/gl.h>
#   include <OpenGLES/ES1/glext.h>
#   ifdef __OBJC__
#       include <OpenGLES/EAGL.h>
#   endif
#	ifndef GL_GLEXT_PROTOTYPES
#		define  GL_GLEXT_PROTOTYPES
#	endif
#else
#   include <GLES/gl.h>
#   include <GLES/glext.h>
#   if (U2_PLATFORM == U2_PLATFORM_ANDROID)
#       include <EGL/egl.h>
#   else
#       include <GLES/egl.h>
#   endif

// If we are going to use the PVRTC_CODEC make sure we
// setup the needed constants
#   if (U2_NO_PVRTC_CODEC == 0)
#	    ifndef GL_IMG_texture_compression_pvrtc
#		    define GL_IMG_texture_compression_pvrtc                 1
#		    define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG               0x8C00
#		    define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG               0x8C01
#		    define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG              0x8C02
#		    define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG              0x8C03
#	    endif
#   endif

// Function pointers for FBO extension methods
// Declare them here since we don't have GLEW to do it for us

#	ifndef GL_GLEXT_PROTOTYPES
    extern PFNGLISRENDERBUFFEROESPROC glIsRenderbufferOES;
    extern PFNGLBINDRENDERBUFFEROESPROC glBindRenderbufferOES;
    extern PFNGLDELETERENDERBUFFERSOESPROC glDeleteRenderbuffersOES;
    extern PFNGLGENRENDERBUFFERSOESPROC glGenRenderbuffersOES;
    extern PFNGLRENDERBUFFERSTORAGEOESPROC glRenderbufferStorageOES;
    extern PFNGLGETRENDERBUFFERPARAMETERIVOESPROC glGetRenderbufferParameterivOES;
    extern PFNGLISFRAMEBUFFEROESPROC glIsFramebufferOES;
    extern PFNGLBINDFRAMEBUFFEROESPROC glBindFramebufferOES;
    extern PFNGLDELETEFRAMEBUFFERSOESPROC glDeleteFramebuffersOES;
    extern PFNGLGENFRAMEBUFFERSOESPROC glGenFramebuffersOES;
    extern PFNGLCHECKFRAMEBUFFERSTATUSOESPROC glCheckFramebufferStatusOES;
    extern PFNGLFRAMEBUFFERRENDERBUFFEROESPROC glFramebufferRenderbufferOES;
    extern PFNGLFRAMEBUFFERTEXTURE2DOESPROC glFramebufferTexture2DOES;
    extern PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVOESPROC glGetFramebufferAttachmentParameterivOES;
    extern PFNGLGENERATEMIPMAPOESPROC glGenerateMipmapOES;
    extern PFNGLBLENDEQUATIONOESPROC glBlendEquationOES;
    extern PFNGLBLENDFUNCSEPARATEOESPROC glBlendFuncSeparateOES;
    extern PFNGLBLENDEQUATIONSEPARATEOESPROC glBlendEquationSeparateOES;
    extern PFNGLMAPBUFFEROESPROC glMapBufferOES;
    extern PFNGLUNMAPBUFFEROESPROC glUnmapBufferOES;
#	endif

#endif


#if (U2_PLATFORM == U2_PLATFORM_WIN32)
#	if !defined( __MINGW32__ )
#		ifndef WIN32_LEAN_AND_MEAN
#			define WIN32_LEAN_AND_MEAN  1
#		endif
#		ifndef NOMINMAX
#			define NOMINMAX // required to stop windows.h messing up std::min
#		endif
#	endif
#endif


// ////////////////////////// DLL //////////////////////////////
#if U2_PLATFORM == U2_PLATFORM_WIN32
#	ifdef U2_GLES_PLUGIN_EXPORTS
#		    define _U2GLESShare				__declspec(dllexport)
#		    define _U2GLESPrivate
#	else
#       if defined( __MINGW32__ )
#           define _U2GLESShare
#       else
#		    define _U2GLESShare				__declspec(dllimport)
#       endif
#		    define _U2GLESPrivate
#	endif
#elif U2_PLATFORM == U2_PLATFORM_LINUX || U2_PLATFORM == U2_PLATFORM_APPLE || U2_PLATFORM == U2_PLATFORM_APPLE_IOS || \
    U2_PLATFORM == U2_PLATFORM_ANDROID || U2_PLATFORM == U2_PLATFORM_TEGRA2
#	ifdef U2_GLES_PLUGIN_EXPORTS
#		define _U2GLESShare				__attribute__ ((visibility("default")))
#		define _U2GLESPrivate			__attribute__ ((visibility("hidden")))
#	else  
#		define _U2GLESShare
#		define _U2GLESPrivate
#	endif
#endif




// Define GL_NONE for convenience
#define GL_NONE                         0


#ifndef GL_BGRA
#   define GL_BGRA                      0x80E1
#endif


// OpenGL Debug
#define ENABLE_GL_CHECK                 1

#if ENABLE_GL_CHECK
#   define GL_CHECK_ERROR \
    { \
        int e = glGetError(); \
        if (e != 0) \
        { \
            fprintf(stderr, "OpenGL error 0x%04X in %s at line %i in %s\n", e, __FUNCTION__/*__PRETTY_FUNCTION__*/, __LINE__, __FILE__); \
        } \
    }
#else
#   define GL_CHECK_ERROR               {}
#endif

//char str1[256]; \
//sprintf(str1, "OpenGL error 0x%04X in %s at line %i in %s\n", e, __FUNCTION__/*__PRETTY_FUNCTION__*/, __LINE__, __FILE__); \
//OutputDebugString(str1); \

#if ENABLE_GL_CHECK
#   define EGL_CHECK_ERROR \
    { \
        int e = eglGetError(); \
        if ((e != 0) && (e != EGL_SUCCESS))\
        { \
            fprintf(stderr, "OpenGL error 0x%04X in %s at line %i in %s\n", e, __PRETTY_FUNCTION__, __LINE__, __FILE__); \
            assert(false); \
        } \
    }
#else
#   define EGL_CHECK_ERROR              {}
#endif


#endif